package cn.lzj.org.service.impl;

import cn.lzj.basic.util.PageList;
import cn.lzj.org.domain.Department;
import cn.lzj.org.mapper.DepartmentMapper;
import cn.lzj.org.query.DepartmentQuery;
import cn.lzj.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
//开启业务层的支持
@Service
//只读事务,全局默认是如果Bean调用事务就执行,如果没有就不用事务
@Transactional(readOnly = true,propagation = Propagation.REQUIRED)  
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    //注入mapper层
    private DepartmentMapper departmentMapper;

    @Override
    @Transactional
    public void add(Department departmentart) {
        departmentMapper.save(departmentart);
    }

    @Override
    @Transactional
    public void update(Department departmentart) {
        departmentMapper.update(departmentart);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    public Department queryById(Long id) {
        return departmentMapper.loadById(id);
    }

    @Override
    public List<Department> queryAll() {
        return departmentMapper.loadAll();
    }

    @Override
    public PageList<Department> queryPage(DepartmentQuery query) {
        //查询页面数据的总条数
        Long tatal = departmentMapper.queryCount(query);
        //查询当前页的数据
        List<Department> rows = departmentMapper.queryData(query);
        return new PageList<>(tatal, rows);
    }
}
